package club.monkeywood.repository;

import club.monkeywood.dto.buyer.RatingDTO;
import club.monkeywood.dataobject.Rating;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RatingRepository extends JpaRepository<Rating, Integer> {

    List<Rating> findAllBySellerId(Sort sort, Integer id);

    @Query(value="select new club.monkeywood.dto.buyer.RatingDTO(" +
            " a.id, b.name, a.rateTime, a.deliveryTime, " +
            " a.score, a.rateType, a.text, " +
            " b.avatar, a.productionId) " +
            " from Rating a,Buyer b " +
            " where a.buyerId=b.id " +
            " and a.sellerId=:sellerId")
    List<RatingDTO> queryBySellerId(@Param("sellerId") Integer sellerId);

}
